/////////////////////////////////////////////
//PDAnnotListData
/////////////////////////////////////////////
function PDAnnotListData(pdPage)
{
	this.m_nVersion = null;
	this.m_nAnnotCount = null;
	this.m_wsImgPath = null;
	this.m_AnnotList = [];
	this.m_pdPage = pdPage;

    //for icon
    this.m_nFixedIconType = 0;
    this.m_szIcon = [0, 0];
    this.m_nRotate = 0;
	
	this.setImgPath = function (wsImgPath)
	{
		this.m_wsImgPath = wsImgPath;
	};
	this.getImgPath = function ()
	{
		return this.m_wsImgPath;
	};
	this.getAnnotCount = function()
	{
		return this.m_nAnnotCount;
	};
	this.getAnnotDataByIndex = function (nIndex)
	{
		return this.m_AnnotList[nIndex];
	};
	this.getAnnotDataById = function(id){
		for(var i = 0;i < this.m_AnnotList.length;i++){
			if(id == this.m_AnnotList[i].m_nID){
				return this.m_AnnotList[i];
			}
		}
	};
	this.parseAnnotListData = function (rd)
	{
		this.m_nVersion = rd.readUint16();
		this.m_nAnnotCount = rd.readInt32();
		if (this.m_nAnnotCount > 0)
		{
			for (var i = 0; i < this.m_nAnnotCount; ++ i)
			{
				var AnnotData = new PDAnnotData(this.m_pdPage);
				AnnotData.setImgPath(this.getImgPath());
				AnnotData.parseAnnotData(rd);
				this.m_AnnotList[i] = AnnotData;
            }
        }
    };
    //this function just append ap form to render
    this.ShowAnnots = function (renderContext, mtObj2Device, bShowWidget) {
        this.DisplayAnnots(renderContext, mtObj2Device, bShowWidget ? 3 : 1);
    };
    this.DisplayAnnots = function (renderContext, mtObj2Device, dwAnnotFlags) {
        // First display non-widget annotations
        if (dwAnnotFlags & 0x01)
            this.DisplayPass(renderContext, mtObj2Device, false);

        // now display widget annotations
        if (dwAnnotFlags & 0x02)
            this.DisplayPass(renderContext, mtObj2Device, true);
    };

    this.DisplayPass = function (renderContext, mtObj2Device, bWidgetPass) {
        var nAnnots = this.getAnnotCount();
        for (var i = 0; i < nAnnots; i++) {
            var annot = this.getAnnotDataByIndex(i);
            if (annot == null) continue;
            var bWidget = annot.m_strSubName == "Widget";
            if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget)) continue;

            // Check annotation flags
            annot_flags = annot.m_nFlag;
            if (annot_flags & 2) continue; // hidden
            if (annot_flags & 0x20) continue; // no-view annot

            var matrix = this.GetAnnotMatrix(annot, mtObj2Device);
            annot.DrawInContext(renderContext, matrix, 0);
        }


    };
    this.SetFixedIconParams = function (nFixedIconType, sx, sy, nRotate) {
        this.m_nFixedIconType = nFixedIconType % 4;
        this.m_szIcon.x = sx;
        this.m_szIcon.y = sy;
        this.m_nRotate = nRotate;
    };
    this.GetAnnotMatrix = function (annot, mtObj2Deviece) {
        var mt = new PDMatrix();
        mt.Clon(mtObj2Deviece);
        if (this.m_nFixedIconType == 0) return mt;
    };



}

///////////////////////////////////////////////
//CPDAnnotData
///////////////////////////////////////////////
function PDAnnotData(pdPage)
{
//****************************attribute**************************************
	this.m_nID = null;
	this.m_wsImgPath = null;		//ImgPath
	this.m_strSubName = null;		//subtype
	this.m_fRect = [];				//Rect
	this.m_chContents = null;		//Contents
	this.m_chAS = null;				//AS
	this.m_structBS = {};			//BS
	this.m_chMainName = null;		//MN
	this.m_chDate = null;			//M(Modify Date)
	this.m_nFlag = 0;				//Flag
	this.m_structBorder = {};		//Border
	this.m_color = [];				//C
	this.m_structAction = {};		//A
	this.m_nStructParent;			//StructParent
	this.m_structOC = {};			//OC
	this.m_structUsage = {};		//Dic Usage in structOC
	this.m_chAuthor = null;			//T
	this.m_appearence = null;		//AP
	this.m_AddEntries = {};			//AnnotAdditionEntries
	this.m_pdPage = pdPage;

	//apMode : 0 for Normal, 1 for Rollover, 2 for Down
	this.DrawInContext = function (renderContext, mtObj2Device, apMode) {

	    //if has external annot handler, we should just use handler to display;

        //now, display annot self;
	    if (this.m_appearence == null || this.m_appearence.m_pdForm == null) return;

	    var objs = this.m_appearence.m_pdForm.GetPageObjects();
	    if (null == objs) return;

	    var formBbox = objs.m_BBox;
	    var formMatrix = objs.matrix;
	    var bbox = formMatrix.TransFormRect(formBbox[0], formBbox[1], formBbox[2], formBbox[3]);
	    var matrix = new PDMatrix();
	    matrix.MatchRect(this.m_fRect, bbox);
	    matrix.Concat(mtObj2Device.a, mtObj2Device.b, mtObj2Device.c, mtObj2Device.d, mtObj2Device.e, mtObj2Device.f, false);

	    renderContext.AppandObjList(objs, matrix);

	};
	
//*****************************function******************************
	this.setImgPath = function(wsImgPath)
	{
		this.m_wsImgPath = wsImgPath;
	};
	
	this.parseAnnotData = function (rd)
	{
		if (rd == null)
		{
			throw("解析数据异常!");
			return;
		}
		this.parseCommonEntries(rd);
		this.parseAdditionalEntries(rd);
	};
	
	this.parseCommonEntries = function (rd)
	{
		this.m_nID = rd.readInt32();
		var nNameLen = rd.readUint8();
		this.m_strSubName = rd.readString(nNameLen);
		this.m_fRect[0] = rd.readFloat32();
		this.m_fRect[1] = rd.readFloat32();
		this.m_fRect[2] = rd.readFloat32();
		this.m_fRect[3] = rd.readFloat32();
		this.m_chContents = getWideStringValue(rd);
		this.m_chAS = getStringValue(rd);
		var nUseFlag = rd.readUint8();
		if (nUseFlag != 0)			//BorderStyle
		{
			this.parseBorderStyle(this.m_structBS, rd);
		}
		this.m_chMainName = getStringValue(rd);
		this.m_chDate = getStringValue(rd);
		this.m_nFlag = rd.readInt32();
		this.parseBorder(this.m_structBorder, rd);
		var nColorCount = rd.readUint8();
		if (nColorCount > 0)
		{
			for (var i = 0; i < nColorCount; ++ i)
			{
				this.m_color[i] = rd.readFloat32();
			}
		}
		var nUseFlag = rd.readUint8();
		if (nUseFlag != 0)			//A
		{
			parseAction(this.m_structAction, rd);	
		}
		this.m_nStructParent = rd.readInt32();
		var nUseFlag = rd.readUint8();
		if (nUseFlag != 0)			//OC
		{
			this.parseOptionalContent(this.m_structOC, rd);
		}
		this.m_chAuthor = getWideStringValue(rd);		//T
		
		var nUseFlag = rd.readUint8();
		if (nUseFlag != 0)			//AP
		{
			this.m_appearence = {};
		
			this.m_appearence.m_BBox = new Array();
			this.m_appearence.m_BBox[0] = rd.readFloat32();
			this.m_appearence.m_BBox[1] = rd.readFloat32();
			this.m_appearence.m_BBox[2] = rd.readFloat32();
			this.m_appearence.m_BBox[3] = rd.readFloat32();
			
			this.m_appearence.m_fMatrix = new PDMatrix();
			var fA = rd.readFloat32();
			var fB = rd.readFloat32();
			var fC = rd.readFloat32();
			var fD = rd.readFloat32();
			var fE = rd.readFloat32();
			var fF = rd.readFloat32();
			this.m_appearence.m_fMatrix.Set(fA, fB, fC, fD, fE, fF);
			
			//this.m_appearence.m_pdForm = new PDForm(this.m_wsImgPath);
			this.m_appearence.m_pdForm = new PDForm(this.m_pdPage.GetPDDoc(), this.m_wsImgPath);
			this.m_appearence.m_pdForm.ParseFromBin(rd);
		}
	};
	
	this.parseAdditionalEntries = function (rd)
	{
		if (this.m_strSubName == "Text")
		{
			this.parseTextAnnot(rd);
		} 
		else if (this.m_strSubName == "Link")
		{
			this.parseLinkAnnot(rd);
		}
		else if (this.m_strSubName == "Line")
		{
			this.parseLineAnnot(rd);
		}
		else if (this.m_strSubName == "FreeText")
		{
			this.parseFreeTextAnnot(rd);
		}
		else if (this.m_strSubName == "Square" || this.m_strSubName == "Circle")
		{
			this.parseSquareOrCircleAnnot(rd);
		}
		else if (this.m_strSubName == "Polygon" || this.m_strSubName == "PolyLine")
		{
			this.parsePolygonOrPolylineAnnot(rd);
		}
		else if (this.m_strSubName == "Highlight" || this.m_strSubName == "Underline" || this.m_strSubName == "Squiggly" || this.m_strSubName == "StrikeOut")
		{
			this.parseTextMarkupAnnot(rd);
		}
		else if (this.m_strSubName == "Stamp")
		{
			this.parseStampAnnot(rd);
		}
		else if (this.m_strSubName == "Caret")
		{
			this.parseCaretAnnot(rd);
		}
		else if (this.m_strSubName == "Ink")
		{
			this.parseInkAnnot(rd);
		}
		else if (this.m_strSubName == "Popup")
		{
			this.parsePopUpAnnot(rd);
		}
		else if (this.m_strSubName == "Widget")
		{
			this.parseWidgetAnnot(rd);
		}
	};
	
//******************************************************************************
	this.parseTextAnnot = function (rd)
	{
		this.m_AddEntries.m_bOpen = rd.readUint8();
		this.m_AddEntries.m_chName = getStringValue(rd);
		this.m_AddEntries.m_chState = getStringValue(rd);
		this.m_AddEntries.m_chStateModel = getStringValue(rd);
	};
	this.parseLinkAnnot = function (rd)
	{
		var nUseFlag = rd.readUint8();
		this.m_AddEntries.m_structA = {};
		if (nUseFlag != 0)
		{
			parseAction(this.m_AddEntries.m_structA, rd);
		}
		this.m_AddEntries.m_chHMode = getStringValue(rd);
		var nUseFlag = rd.readUint8();
		this.m_AddEntries.m_structPA = {};
		if (nUseFlag != 0)
		{
			this.parsePA(this.m_AddEntries.m_structPA, rd);
		}
		var nPointCounts = rd.readInt32();
		this.m_AddEntries.m_arrPoint = [];
		for (var i = 0; i < nPointCounts; ++ i)
		{
			this.m_AddEntries.m_arrPoint[i] = rd.readFloat32();
		}
	};
	this.parseLineAnnot = function (rd)
	{
		this.m_AddEntries.m_arrLine = [];
		this.m_AddEntries.m_arrLine[0] = rd.readFloat32();
		this.m_AddEntries.m_arrLine[1] = rd.readFloat32();
		this.m_AddEntries.m_arrLine[2] = rd.readFloat32();
		this.m_AddEntries.m_arrLine[3] = rd.readFloat32();
		var nUseFlag = rd.readUint8();
		this.m_AddEntries.m_structBS = {};
		if (nUseFlag > 0)
		{
			this.parseBorderStyle(this.m_AddEntries.m_structBS, rd);
		}
		this.m_AddEntries.m_structLE = {};
		this.parseLineEffect(this.m_AddEntries.m_structLE, rd);
		this.m_AddEntries.m_structIC = [];
		this.parseICArray(this.m_AddEntries.m_structIC, rd);
		this.m_AddEntries.m_fLL = rd.readFloat32();
		this.m_AddEntries.m_fLLE = rd.readFloat32();
		this.m_AddEntries.m_bCap = rd.readUint8();
		this.m_AddEntries.m_chIT = getStringValue(rd);	//IT
		this.m_AddEntries.m_fLLO = rd.readFloat32();
		this.m_AddEntries.m_chCP = getStringValue(rd);
		this.m_AddEntries.m_chMeasure = getStringValue(rd);
		this.m_AddEntries.m_fFirstCO = rd.readFloat32();
		this.m_AddEntries.m_fSecondCO = rd.readFloat32();
	};
	this.parseFreeTextAnnot = function (rd)
	{
		this.m_AddEntries.m_chDa = getStringValue(rd);
		this.m_AddEntries.m_nQ = rd.readInt32();
		this.m_AddEntries.m_chRC = getStringValue(rd);
		this.m_AddEntries.m_chDS = getStringValue(rd);
		var nCLCount = rd.readUint8();
		this.m_AddEntries.m_arrCL = [];
		if (nCLCount > 0)
		{
			for (var i = 0; i < nCLCount; ++ i)
			{
				this.m_AddEntries.m_arrCL[i] = rd.readFloat32();
			}
		}
		this.m_AddEntries.m_chIT = getStringValue(rd);
		var nUseFlag = rd.readUint8();
		this.m_AddEntries.m_structBE = {};
		if (nUseFlag != 0)
		{
			this.parseBorderEffect(this.m_AddEntries.m_structBE, rd);
		}
		this.m_AddEntries.m_fRD = [];
		this.m_AddEntries.m_fRD[0] = rd.readFloat32();
		this.m_AddEntries.m_fRD[1] = rd.readFloat32();
		this.m_AddEntries.m_fRD[2] = rd.readFloat32();
		this.m_AddEntries.m_fRD[3] = rd.readFloat32();
		var nUseFlag = rd.readUint8();
		this.m_AddEntries.m_structBS = {};
		if (nUseFlag != 0)
		{
			this.parseBorderStyle(this.m_AddEntries.m_structBS, rd);
		}
		this.m_AddEntries.m_structLE = {};
		this.parseLineEffect(this.m_AddEntries.m_structLE, rd);
	};
	this.parseSquareOrCircleAnnot = function (rd)
	{
		var nUseFlag = rd.readUint8();
		this.m_AddEntries.m_structBS = {};
		if (nUseFlag != 0)
		{
			this.parseBorderStyle(this.m_AddEntries.m_structBS, rd);
		}
		this.m_AddEntries.m_structBS = [];
		this.parseICArray(this.m_AddEntries.m_structBS, rd);
		var nUseFlag = rd.readUint8();
		this.m_AddEntries.m_structBE = {};
		if (nUseFlag != 0)
		{
			this.parseBorderEffect(this.m_AddEntries.m_structBE, rd);
		}
		this.m_AddEntries.m_fRD = [];
		this.m_AddEntries.m_fRD[0] = rd.readFloat32();
		this.m_AddEntries.m_fRD[1] = rd.readFloat32();
		this.m_AddEntries.m_fRD[2] = rd.readFloat32();
		this.m_AddEntries.m_fRD[3] = rd.readFloat32();
	};
	this.parsePolygonOrPolylineAnnot = function (rd)
	{
		var nCount = rd.readUint8();
		this.m_AddEntries.m_arrVertices = [];
		if (nCount > 0)
		{
			for (var i = 0; i < nCount; ++ i)
			{
				this.m_AddEntries.m_arrVertices[i] = rd.readFloat32();
			}
		}
		this.m_AddEntries.m_structLE = {};
		this.parseLineEffect(this.m_AddEntries.m_structLE, rd);
		var nUseFlag = rd.readUint8();
		this.m_AddEntries.m_structBS = {};
		if (nUseFlag != 0)
		{
			this.parseBorderStyle(this.m_AddEntries.m_structBS, rd);
		}		
		this.m_AddEntries.m_arrIC = [];
		this.parseICArray(this.m_AddEntries.m_arrIC, rd);
		var nUseFlag = rd.readUint8();
		this.m_AddEntries.m_structBE = {};
		if (nUseFlag != 0)
		{
			this.parseBorderEffect(this.m_AddEntries.m_structBE, rd);
		}
		this.m_AddEntries.m_chIT = getStringValue(rd);
		this.m_AddEntries.m_chMeadure = getStringValue(rd);
	};
	this.parseTextMarkupAnnot = function (rd)
	{
		var nCount = rd.readInt32();
		this.m_AddEntries.m_arrPoint = [];
		if (nCount > 0)
		{
			for (var i = 0; i < nCount; ++ i)
			{
				this.m_AddEntries.m_arrPoint[i] = rd.readFloat32();
			}
		}
	};
	this.parseStampAnnot = function (rd)
	{
		this.m_AddEntries.m_chName = getStringValue(rd);
	};
	this.parseCaretAnnot = function (rd)
	{
		this.m_AddEntries.m_fRD = [];
		this.m_AddEntries.m_fRD[0] = rd.readFloat32();
		this.m_AddEntries.m_fRD[1] = rd.readFloat32();
		this.m_AddEntries.m_fRD[2] = rd.readFloat32();
		this.m_AddEntries.m_fRD[3] = rd.readFloat32();
		this.m_AddEntries.m_chSy = getStringValue(rd);
	};
	this.parseInkAnnot = function (rd)
	{
		var nPathCount = rd.readInt32();
		this.m_AddEntries.m_strokePath = [];
		if (nPathCount > 0)
		{
			for (var i = 0; i < nPathCount; ++ i)
			{
				var nPointCount = rd.readInt32();
				this.m_AddEntries.m_strokePath[i] = [];
				for (var j = 0; j < nPointCount; ++ j)
				{
					this.m_AddEntries.m_strokePath[i][j] = rd.readFloat32();
				}
			}
		}
		var nUseFlag = rd.readUint8();
		this.m_AddEntries.m_structBS = {};
		if (nUseFlag != 0)
		{
			this.parseBorderStyle(this.m_AddEntries.m_structBS, rd);
		}
	};
	this.parsePopUpAnnot = function (rd)
	{
		this.m_AddEntries.m_nParentID = rd.readInt32();
		this.m_AddEntries.m_bOpen = rd.readUint8();
	};
	this.parseWidgetAnnot = function (rd){
		this.m_AddEntries.m_strHighlightMode = getStringValue(rd);	// H
		var nUseFlag = rd.readUint8();
		if (nUseFlag != 0){				// MK
			this.m_AddEntries.m_entriesMK = {};
			this.m_AddEntries.m_entriesMK.m_nRotation = rd.readInt32();	// R
			var nBCCount = rd.readUint8();		// BC
			if (nBCCount != 0){
				this.m_AddEntries.m_entriesMK.m_BCArray = [];
				for (var i = 0; i < nBCCount; ++ i){
					this.m_AddEntries.m_entriesMK.m_BCArray[i] = rd.readFloat32();
				}
			}
			var nBGCount = rd.readUint8();		// BG
			if (nBGCount != 0){
				this.m_AddEntries.m_entriesMK.m_BGArray = [];
				for (var i = 0; i < nBGCount; ++ i){
					this.m_AddEntries.m_entriesMK.m_BGArray[i] = rd.readFloat32();
				}
			}
			this.m_AddEntries.m_entriesMK.m_CA = getWideStringValue(rd); // CA
			this.m_AddEntries.m_entriesMK.m_RC = getWideStringValue(rd); // RC
			this.m_AddEntries.m_entriesMK.m_AC = getWideStringValue(rd); // AC
			var nIFUseFlag = rd.readUint8();		// IF
			if (nIFUseFlag != 0){
				this.m_AddEntries.m_entriesMK.m_entriesIF = {};
				this.m_AddEntries.m_entriesMK.m_entriesIF.m_strSW = getStringValue(rd);	// SW
				this.m_AddEntries.m_entriesMK.m_entriesIF.m_strS = getStringValue(rd);		// S
				var nACount = rd.readUint8();		// A
				if (nACount != 0){
					this.m_AddEntries.m_entriesMK.m_entriesIF.m_aArray = [];
					for (var i = 0; i < nACount; ++ i){
						this.m_AddEntries.m_entriesMK.m_entriesIF.m_aArray[i] = rd.readFloat32();
					}
				}
				this.m_AddEntries.m_entriesMK.m_entriesIF.m_bFB = rd.readUint8();
			}
			this.m_AddEntries.m_entriesMK.M_nTP = rd.readInt32();	// TP
		}
		var nUseFlag = rd.readUint8();		// A
		if (nUseFlag != 0){
			this.m_AddEntries.m_action = {};
			parseAction(this.m_AddEntries.m_action, rd);
		}
		var nUseFlag = rd.readUint8();		// AA
		if (nUseFlag != 0){
			var nActionCount = rd.readUint8();
			if (nActionCount != 0){
				this.m_AddEntries.m_addAction = [];
				for (var i = 0; i < nActionCount; ++ i){
					this.m_AddEntries.m_addAction[i] = {};
					parseAction(this.m_AddEntries.m_addAction[i], rd);
				}
			}
		}
		
	};
	//************************************************************************
	this.parseBorderStyle = function (structBS, rd)
	{
		structBS.m_nWidth = rd.readInt32();
		structBS.m_chStyle = getStringValue(rd);
		var nDashCount = rd.readUint8();
		structBS.m_arrDash = [];
		if (nDashCount > 0)
		{
			for (var i = 0; i < nDashCount; ++ i)
			{
				structBS.m_arrDash[i] = rd.readInt32();
			}
		}
	};

	this.parseBorder = function (structBorder, rd)
	{
		structBorder.m_fHCornerRadius = rd.readFloat32();
		structBorder.m_fVCornerRadius = rd.readFloat32();
		structBorder.m_fWidth = rd.readFloat32();
		var nDashCount = rd.readUint8();
		structBorder.m_arrDash = [];
		if (nDashCount > 0)
		{
			for (var i = 0; i < nDashCount; ++ i)
			{
				if (i < 3)
				{
					structBorder.m_arrDash[i] = rd.readInt32();
				}
			}
		}
	};
	
	this.parseOptionalContent = function (structOC, rd)
	{
		structOC.m_chName = getStringValue(rd);
		var nIntnetCount = rd.readUint8();
		structOC.m_arrIntent = [];
		if (nIntnetCount > 0)
		{
			for (var i = 0; i < nIntnetCount; ++ i)
			{
				structOC.m_arrIntent[i] = getStringValue(rd);
			}
		}
		var nUseFlag = rd.readUint8();
		structOC.m_structUsege = {};
		if (nUseFlag != 0)
		{
			this.parseUsage(structOC.m_structUsege);
		}
	};

	this.parseUsage = function (structUsage, rd)
	{
		var nUseFlag = rd.readUint8();
		structUsage.m_createInfo = {};
		if (nUseFlag != 0)
		{
			structUsage.m_createInfo.m_chCreator = getStringValue(rd);
		
			structUsage.m_createInfo.m_chSubtype = getStringValue(rd);	//CreaterInfo/Subtype
		}

		var nUseFlag = rd.readUint8();
		structUsage.m_language = {};
		if (nUseFlag != 0)
		{
			structUsage.m_language.m_chLang = getStringValue(rd);			//Language/Lang
			
			structUsage.m_language.m_Pre = getStringValue(rd);		//Language/Preferred
		}
		
		var nUseFlag = rd.readUint8();
		structUsage.m_export = {};
		if (nUseFlag != 0)
		{
			structUsage.m_export.m_chState = getStringValue(rd);		//Export
		}
		
		var nUseFlag = rd.readUint8();
		structUsage.m_zoom = {};
		if (nUseFlag != 0)
		{
			structUsage.m_zoom.m_nMin = rd.readInt32();			//Zoom/Min
			structUsage.m_zoom.m_nMax = rd.readInt32();			//Zoom/Max
		}
		
		var nUseFlag = rd.readUint8();
		structUsage.m_print = {};
		if (nUseFlag != 0)
		{
			structUsage.m_print.m_chSubtype = getStringValue(rd);		//Print/Subtype
			
			structUsage.m_print.m_chState = getStringValue(rd);	//Print/PrintState
		}
		
		var nUseFlag = rd.readUint8();
		structUsage.m_view = {};
		if (nUseFlag != 0)
		{
			structUsage.m_view.m_chState = getStringValue(rd);			//View
		}

		var nUseFlag = rd.readUint8();
		structUsage.m_user = {};
		if (nUseFlag != 0)
		{
			structUsage.m_user.m_chType = getStringValue(rd);			//User/Type
			
			structUsage.m_userm_chName = getStringValue(rd);			//User/Name
		}
		
		var nUseFlag = rd.readUint8();
		structUsage.m_pageElement = {};
		if (nUseFlag != 0)
		{
			structUsage.m_pageElement.m_chState = getStringValue(rd);	//PageElement
		}
	};

	this.parseBorderEffect = function (structBE, rd)
	{
		structBE.m_chStyle = getStringValue(rd);
		structBE.m_fI = rd.readFloat32();
	};

	this.parseLineEffect = function (structLE, rd)
	{
		structLE.m_chBegin = getStringValue(rd);
		structLE.m_chEnd = getStringValue(rd);
	};

	this.parseICArray = function (array, rd)
	{
		var nICCount = rd.readUint8();
		if (nICCount > 0)
		{
			for (var i = 0; i < nICCount; ++ i)
			{
				array[i] = rd.readFloat32();
			}
		}
	};
	this.parsePA = function (structPA, rd)
	{
		structPA.m_chS = getStringValue(rd);
		structPA.m_bIsMap = rd.readUint8();
	};
}

////////////////////////  Global function ///////////////////////////////////
getStringValue = function (rd)
{
	var nstrLen = rd.readUint8();
	if (nstrLen > 0)
	{
		return rd.readString(nstrLen);
	}
	else
		return "";
};
getWideStringValue = function (rd)
{
	var nstrLen = rd.readInt32();
	if (nstrLen > 0)
	{
		return rd.readString(nstrLen);
	}
	else
		return "";
};
parseAction = function (structA, rd)
{
	structA.m_chName = getStringValue(rd);
	structA.m_nActionType = rd.readUint8();
	structA.m_subTypeAction = {};
	parseSubAction(structA.m_subTypeAction, structA.m_nActionType, rd);
	structA.m_subCount = rd.readUint32();
	if (structA.m_subCount > 0)
	{
		structA.m_subAction = [];
		for (var i = 0; i < structA.m_subCount; ++ i)
		{
			var nUseFlag = rd.readUint8();
			if (nUseFlag != 0)
			{
				var subAction = {};
				this.parseAction(subAction, rd);
				structA.m_subAction[i] = subAction;
			}
			else
			{
				structA.m_subAction[i] = null;
			}
		}
	}
};
parseSubAction = function (subActionStruct, actionType, rd)
{
	switch (actionType)
	{
		case 0:
			break;
		case 1:		// GoTo
			var nUseFlag = rd.readUint8();
			if (nUseFlag != 0)
			{
				subActionStruct.m_nPageIndex = rd.readInt32();
				subActionStruct.m_nZoomMode = rd.readInt32();
				subActionStruct.m_fLeft =  rd.readFloat32();
				subActionStruct.m_fTop =  rd.readFloat32();
				subActionStruct.m_fRight =  rd.readFloat32();
				subActionStruct.m_fBottom =  rd.readFloat32();
				subActionStruct.m_fScale =  rd.readFloat32();
			}
			break;
		case 2:		//GoToR
			subActionStruct.m_strFilePath = getWideStringValue(rd);
			var nUseFlag = rd.readUint8();
			if (nUseFlag != 0)
			{
				subActionStruct.m_nPageIndex = rd.readInt32();
				subActionStruct.m_nZoomMode = rd.readInt32();
				subActionStruct.m_fLeft =  rd.readFloat32();
				subActionStruct.m_fTop =  rd.readFloat32();
				subActionStruct.m_fRight =  rd.readFloat32();
				subActionStruct.m_fBottom =  rd.readFloat32();
				subActionStruct.m_fScale =  rd.readFloat32();
			}
			subActionStruct.m_bIsNewWindow = rd.readUint8();
			break;
		case 3:		//GoToE		
			break;
		case 4:		//Launch
			subActionStruct.m_strFilePath = getWideStringValue(rd);
			subActionStruct.m_bIsNewWindow = rd.readUint8();
			var nUseFlag = rd.readUint8();
			if (nUseFlag != 0)
			{
				subActionStruct.m_strFileName = getStringValue(rd);
				subActionStruct.m_strDefaultDirectory = getStringValue(rd);
				subActionStruct.m_strOperation = getStringValue(rd);
				subActionStruct.m_strParameter = getStringValue(rd);
			}
			break;
		case 5:		//Thread
			break;
		case 6:		//URI
			subActionStruct.m_strURI = getStringValue(rd);
			subActionStruct.m_bIsMap = rd.readUint8();
			break;
		case 7:		//Sound
			break;
		case 8:		//Movie
			break;
		case 9:		//Hide
			break;
		case 10:	//Named
			subActionStruct.m_strNamedAction = getStringValue(rd);
			break;
		case 11:	//SubmitForm
			subActionStruct.m_strFullPath = getWideStringValue(rd);
			subActionStruct.m_nFlags = rd.readUint32();
			subActionStruct.m_nFieldsCount = rd.readUint8();
			if (subActionStruct.m_nFieldsCount != 0){
				subActionStruct.m_arrFields = [];
				for (var i = 0; i < subActionStruct.m_nFieldsCount; ++ i){
					subActionStruct.m_arrFields[i] = getStringValue(rd);
				}
			}
			break;
		case 12:	//ResetForm
			subActionStruct.m_dwFlag = rd.readUint32();
			subActionStruct.m_nFieldsCount = rd.readUint8();
			if (subActionStruct.m_nFieldsCount != 0){
				subActionStruct.m_arrFields = [];
				for (var i = 0; i < subActionStruct.m_nFieldsCount; ++ i){
					subActionStruct.m_arrFields[i] = getStringValue(rd);
				}
			}
			break;
		case 13:	//ImportData
			subActionStruct.m_strFilePath = getWideStringValue(rd);
			break;
		case 14:	//JavaScript
			subActionStruct.m_strJavaScript = getWideStringValue(rd);
			break;
		case 15:	//SetOCGState
			var nStateCount = rd.readInt32();
			if (nStateCount != 0){
				subActionStruct.m_arrState = [];
				for (var i = 0; i < nStateCount; ++ i){
					subActionStruct.m_arrState[i] = getStringValue(rd);
				}
			}
			subActionStruct.m_bPreserveRB = rd.readUint8();
			break;
		case 16:	//Rendition
			break;
		case 17:	//Trans
			break;
		case 18:	//GoTo3DView
			break;
	}
};












